//
//  UpdateUserInfoViewController.m
//  QSBK
//
//  Created by Eric Wang on 5/7/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//

#import "UpdateUserInfoViewController.h"
#import "UserInfoItem.h"
#import "UserDetailInfoCell.h"
static const NSString *str = @"UserInfoChanges";
@interface UpdateUserInfoViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *topBar;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *itemArray;
- (IBAction)saveInfo:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *saveInfoButton;
@property(nonatomic,assign)BOOL isChages;
- (IBAction)back:(id)sender;

@end

@implementation UpdateUserInfoViewController

-(NSMutableArray *)itemArray
{
    if(_itemArray == nil)
    {
        _itemArray = [[NSMutableArray alloc]init];
    }
    
    return _itemArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubviews];
    [self configData];
    // Do any additional setup after loading the view from its nib.
}

-(void)configSubviews
{
    
    self.topBar.backgroundColor = [UIColor colorWithRed:127/255.0 green:146/255.0 blue:254/255.0 alpha:1.0];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    
    [self.saveInfoButton.layer setCornerRadius:3];
    self.saveInfoButton.backgroundColor = [UIColor colorWithRed:194/255.0 green:194/255.0 blue:194/255.0 alpha:1.0];
}

-(void)configData
{
    UserInfoItem *item2 = [[UserInfoItem alloc]init];
    item2.itemTitle = @"头像";
    item2.itemStyle = UserInfoItemImageStyle;
    item2.itemImage = self.user.icon;
    
    UserInfoItem *item3 = [[UserInfoItem alloc]init];
    item3.itemTitle = @"昵称";
    item3.itemStyle = UserInfoItemTextStyle;
    item3.itemDetail = self.user.login;
    
    UserInfoItem *item4 = [[UserInfoItem alloc]init];
    item4.itemTitle = @"性别";
    item4.itemStyle = UserInfoItemTextStyle;
    item4.itemDetail = @"";
    
    UserInfoItem *item5 = [[UserInfoItem alloc]init];
    item5.itemTitle = @"生日";
    item5.itemStyle = UserInfoItemTextStyle;
    item5.itemDetail = @"";
    
    UserInfoItem *item6 = [[UserInfoItem alloc]init];
    item6.itemTitle = @"职业";
    item6.itemStyle = UserInfoItemTextStyle;
    item6.itemDetail = self.user.role;
    
    UserInfoItem *item7 = [[UserInfoItem alloc]init];
    item7.itemTitle = @"家乡";
    item7.itemStyle = UserInfoItemTextStyle;
    item7.itemDetail = self.user.last_visited_at;
    
    UserInfoItem *item8 = [[UserInfoItem alloc]init];
    item8.itemTitle = @"机型";
    item8.itemStyle = UserInfoItemTextStyle;
    item8.itemDetail = self.user.last_device;
    
    UserInfoItem *item9 = [[UserInfoItem alloc]init];
    item9.itemTitle = @"状态";
    item9.itemStyle = UserInfoItemTextStyle;
    item9.itemDetail = self.user.stater;
    
    [self.itemArray addObject:item2];
    [self.itemArray addObject:item3];
    [self.itemArray addObject:item4];
    [self.itemArray addObject:item5];
    [self.itemArray addObject:item6];
    [self.itemArray addObject:item7];
    [self.itemArray addObject:item8];
    [self.itemArray addObject:item9];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.itemArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UserDetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(cell==nil)
    {
        cell = [[UserDetailInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    cell.infoItem = self.itemArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0;
}
- (IBAction)saveInfo:(id)sender {
    
}
- (IBAction)back:(id)sender {
    

        [self dismissViewControllerAnimated:YES completion:nil];

}


-(void)userInfoChanges
{
    self.isChages = YES;
}
@end
